package com.challenge.controller;

import com.alibaba.fastjson.JSONObject;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

/**
 * @Description: // 类说明，在创建类时要填写
 * @ClassName: LineDeomTest    // 类名，会自动填充
 * @Author: weisn          // 创建者
 * @Date: 2021/7/9 17:04   // 时间
 * @Version: 1.0     // 版本
 */
@Controller
public class LineDeomTest {

    @RequestMapping("/line/echarts")
    @ResponseBody
    public JSONObject echart_ajax()
    {
        JSONObject jsonObject=new JSONObject();
        SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date dateTime=new Date();
        Calendar cal = Calendar.getInstance();
        cal.setTime(dateTime);
      //  String formatStr =formatter.format(new Date());
       List<Integer> list=new ArrayList<>();
       List<String> dateList=new ArrayList<>();
       for(int i=0;i<20;i++){
           cal.add(Calendar.SECOND,i);
//           Attention attention=new Attention();
//           attention.setDateTime(cal.getTime());
//           attention.setStatus(Math.random()>0.5?1:0);//随机生成0,1

           dateList.add(simpleDateFormat.format(cal.getTime()));
           cal.add(Calendar.SECOND,-i);
           list.add(Math.random()>0.5?1:0);
       }
       jsonObject.put("dateList",dateList);
       jsonObject.put("dataList",list);
//        System.out.println(list);
        System.out.println(jsonObject);
        return jsonObject;
    }
}
